5
5
class SearchPage (BasePage ):
6
6
# Locators belonging to the searchbar.
7
7
SEARCHBAR_LOCATORS = {
8
- "searchbar" : "//form[@id='support-search-masthead']/input[@id='search-q']" ,
8
+ "searchbar_homepage" : "//form[@id='support-search-masthead']/input[@id='search-q']" ,
9
+ "searchbar_aaq" : "//form[@id='question-search-masthead']/input[@id='search-q']" ,
10
+ "searchbar_sidebar" : "//form[@id='support-search-sidebar']/input[@id='search-q']" ,
11
+ "hidden_searchbar" : "//form[@id='hidden-search']/input[@id='search-q']" ,
9
12
"searchbar_search_button" : "//form[@id='support-search-masthead']/button" ,
10
13
"search_results_header" : "//div[@class='home-search-section--content']/h2" ,
11
- "popular_searches" : "//p[@class='popular-searches']/a"
14
+ "popular_searches" : "//p[@class='popular-searches']/a" ,
15
+ "search_results_section" : "//main[@id='search-results-list']"
12
16
}
13
17
14
18
# Locators belonging to the search results filter
@@ -41,6 +45,9 @@ class SearchPage(BasePage):
41
45
def __init__ (self , page : Page ):
42
46
super ().__init__ (page )
43
47
48
+ def _wait_for_visibility_of_search_results_section (self ):
49
+ self ._wait_for_selector (self .SEARCHBAR_LOCATORS ["search_results_section" ])
50
+
44
51
"""
45
52
Actions against the search results
46
53
"""
@@ -58,6 +65,7 @@ def get_search_result_summary_text_of_a_particular_article(self, article_title)
58
65
Args:
59
66
article_title (str): The title of the article
60
67
"""
68
+ self ._wait_for_visibility_of_search_results_section ()
61
69
return self ._get_text_of_element (f"//h3[@class='sumo-card-heading']/"
62
70
f"a[normalize-space(text())='{ article_title } ']/../"
63
71
f"../p" )
@@ -68,6 +76,7 @@ def is_a_particular_article_visible(self, article_title: str) -> bool:
68
76
Args:
69
77
article_title (str): The title of the article
70
78
"""
79
+ self ._wait_for_visibility_of_search_results_section ()
71
80
return self ._is_element_visible (f"//h3[@class='sumo-card-heading']/"
72
81
f"a[normalize-space(text())='{ article_title } ']" )
73
82
@@ -77,11 +86,13 @@ def click_on_a_particular_article(self, article_title: str):
77
86
Args:
78
87
article_title (str): The title of the article
79
88
"""
89
+ self ._wait_for_visibility_of_search_results_section ()
80
90
self ._click (f"//h3[@class='sumo-card-heading']/"
81
91
f"a[normalize-space(text())='{ article_title } ']" )
82
92
83
93
def get_all_bolded_content (self ) -> list [str ]:
84
94
"""Get all the bolded content of the search results"""
95
+ self ._wait_for_visibility_of_search_results_section ()
85
96
return self ._get_text_of_elements (self .SEARCH_RESULTS_LOCATORS
86
97
["all_bolded_article_content" ])
87
98
@@ -91,6 +102,7 @@ def get_all_search_results_article_bolded_content(self, article_title: str) -> l
91
102
Args:
92
103
article_title (str): The title of the article
93
104
"""
105
+ self ._wait_for_visibility_of_search_results_section ()
94
106
if "'" in article_title :
95
107
parts = article_title .split ("'" )
96
108
if len (parts ) > 1 :
@@ -110,10 +122,12 @@ def get_all_search_results_article_bolded_content(self, article_title: str) -> l
110
122
111
123
def get_all_search_results_article_titles (self ) -> list [str ]:
112
124
"""Get all the titles of the search results"""
125
+ self ._wait_for_visibility_of_search_results_section ()
113
126
return self ._get_text_of_elements (self .SEARCH_RESULTS_LOCATORS ["search_results_titles" ])
114
127
115
128
def get_all_search_results_articles_summary (self ) -> list [str ]:
116
129
"""Get all the summaries of the search results"""
130
+ self ._wait_for_visibility_of_search_results_section ()
117
131
return self ._get_text_of_elements (self .SEARCH_RESULTS_LOCATORS
118
132
["search_results_articles_summary" ])
119
133
@@ -123,6 +137,7 @@ def get_locator_of_a_particular_article(self, article_title: str) -> Locator:
123
137
Args:
124
138
article_title (str): The title of the article
125
139
"""
140
+ self ._wait_for_visibility_of_search_results_section ()
126
141
return self ._get_element_locator (f"//h3[@class='sumo-card-heading']/"
127
142
f"a[normalize-space(text())='{ article_title } ']" )
128
143
@@ -136,20 +151,38 @@ def is_search_content_section_displayed(self) -> bool:
136
151
137
152
def get_text_of_searchbar_field (self ) -> str :
138
153
"""Get the text of the search bar field"""
139
- return self ._get_element_input_value (self .SEARCHBAR_LOCATORS ["searchbar " ])
154
+ return self ._get_element_input_value (self .SEARCHBAR_LOCATORS ["searchbar_homepage " ])
140
155
141
- def fill_into_searchbar (self , text : str ):
156
+ def fill_into_searchbar (self , text : str , is_aaq = False , is_sidebar = False ):
142
157
"""Fill into the search bar
143
158
144
159
Args:
145
160
text (str): The text to fill into the search bar
161
+ is_aaq (bool): Whether the search bar is on the AAQ flow pages
162
+ is_sidebar (bool): Whether the search bar is on the sidebar
146
163
"""
147
- self .clear_the_searchbar ()
148
- self ._fill (self .SEARCHBAR_LOCATORS ["searchbar" ], text )
164
+ if is_aaq :
165
+ self .clear_the_searchbar (is_aaq = True )
166
+ self ._fill (self .SEARCHBAR_LOCATORS ["searchbar_aaq" ], text )
167
+ elif is_sidebar :
168
+ self ._fill (self .SEARCHBAR_LOCATORS ["searchbar_sidebar" ], text )
169
+ else :
170
+ self .clear_the_searchbar ()
171
+ self ._fill (self .SEARCHBAR_LOCATORS ["searchbar_homepage" ], text )
172
+
173
+ def clear_the_searchbar (self , is_aaq = False , is_sidebar = False ):
174
+ """Clear the search bar
149
175
150
- def clear_the_searchbar (self ):
151
- """Clear the search bar"""
152
- self ._clear_field (self .SEARCHBAR_LOCATORS ["searchbar" ])
176
+ Args:
177
+ is_aaq (bool): Whether the search bar is on the AAQ flow pages
178
+ is_sidebar (bool): Whether the search bar is on the sidebar
179
+ """
180
+ if is_aaq :
181
+ self ._clear_field (self .SEARCHBAR_LOCATORS ["searchbar_aaq" ])
182
+ elif is_sidebar :
183
+ self ._clear_field (self .SEARCHBAR_LOCATORS ["hidden_searchbar" ])
184
+ else :
185
+ self ._clear_field (self .SEARCHBAR_LOCATORS ["searchbar_homepage" ])
153
186
154
187
def click_on_search_button (self ):
155
188
"""Click on the search button"""
@@ -188,4 +221,5 @@ def click_on_a_particular_side_nav_item(self, product_name: str):
188
221
"""
189
222
def get_search_results_header (self ) -> str :
190
223
"""Get the search results header"""
224
+ self ._wait_for_visibility_of_search_results_section ()
191
225
return self ._get_text_of_element (self .SEARCHBAR_LOCATORS ["search_results_header" ])
0 commit comments